package com.woniuxy.util;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @ClassName JDKProxyInstance
 * @Description TODO
 * @Author LI.hh
 * @Date 2022/8/22 18:53
 * @Version 1.0
 */
public class JDKProxyInstance {
    public Object getSon(Object object){
        return Proxy.newProxyInstance(object.getClass().getClassLoader(), object.getClass().getInterfaces(),
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("方法"+method.getName()+"进入一次");
                        Object invoke= method.invoke(object, args);
                        System.out.println("方法"+method.getName()+"退出一次");
                        return invoke;
                    }
                });
    }
}
